{extend name="../../public/admin"}
{block name="title"}{:lang('添加土建')}{/block}
{block name="css"}

<script src="__PUBLIC__/public/validform/Validform_v5.3.2_min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/public/validform/style.css">
<!--图片-->
<link rel="stylesheet" href="__PUBLIC__/public/bian-ji-qi/themes/default/default.css" />
<script src="__PUBLIC__/public/bian-ji-qi/kindeditor.js"></script>
<script src="__PUBLIC__/public/bian-ji-qi/lang/zh_CN.js"></script>
<script>
    KindEditor.ready(function(K) {
        var editor = K.editor({
            allowFileManager : true
        });

        K('#image3').click(function() {
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    imageUrl : K('#url3').val(),
                    clickFn : function(url, title, width, height, border, align) {
                        K('#url3').val(url);
                        editor.hideDialog();
                    }
                });
            });
        });
        K('#image4').click(function() {
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    imageUrl : K('#url4').val(),
                    clickFn : function(url, title, width, height, border, align) {
                        K('#url4').val(url);
                        editor.hideDialog();
                    }
                });
            });
        });
    });

</script>
{/block}
{block name="body"}

<div id="container">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">{:lang('添加土建')}</a></li>
    </ul>

    <div style="height: 20px;"></div>
    <div>
        <form action="{:url('upindex')}" method="post" id="form0" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{$data.id}">
            <div class="row">
                <div class="pull-left col-xs-4">
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">创建年份</label>
                        <input type="text" name="date" class="form-control" datatype="n4-4" id="date" value="{$data.date}">
                    </div>

                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">{:lang('规划资金')}</label>
                        <input type="text" name="money" class="form-control" datatype="n1-10" value="{$data.money}">
                    </div>
                    <small class="text-info">{:lang('规划资金')}图</small>
                    <div class="form-group input-group  select-right">
                        <input type="text" name="money_img" class="form-control" datatype="*" id="url3" value="{$data.money_img}">
                        <label class="input-group-addon" id="image3">上传</label>
                    </div>
                    {:lang('规划资金组成情况')}
                    <small class="text-info">提示：四项的合必须等于{:lang('规划资金')}</small>
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">中央资金</label>
                        <input type="text" name="address1" class="form-control" datatype="n1-10" value="{$data.address1}">
                    </div>
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">自&nbsp;&nbsp;治&nbsp;&nbsp;区</label>
                        <input type="text" name="address2" class="form-control" datatype="n1-10" value="{$data.address2}">
                    </div>
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">市级金额</label>
                        <input type="text" name="address3" class="form-control" datatype="n1-10" value="{$data.address3}">
                    </div>
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">旗县金额</label>
                        <input type="text" name="address4" class="form-control" datatype="n1-10" value="{$data.address4}">
                    </div>
                </div>
                <div class="pull-left col-xs-4">
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">{:lang('项目名称')}</label>
                        <input type="text"  class="form-control" datatype="s1-30" value="{$data.name}" disabled>
                    </div>
                    <div class="form-group input-group   select-right">
                        {eq name="$Request.param.type" value="1"}
                        <label class="input-group-addon">购置数量</label>
                        {else/}
                        <label class="input-group-addon">{:lang('面积')}</label>
                        {/eq}

                        <input type="text" name="count" class="form-control" datatype="s1-50" value="{$data.count}">
                    </div>
                    <div class="form-group input-group  select-right" >
                        <label class="input-group-addon">{:lang('建设类型')}</label>
                        <select  name="type" id="select" class="form-control" datatype="*">
                            {eq name="$Request.param.type" value="1"}
                            <option value="5">设备购置</option>
                            {else/}
                            <option value="0" >{:lang('新建')}</option>
                            <option value="1">{:lang('扩建')}</option>
                            <option value="2">{:lang('维修')}</option>
                            <option value="3">{:lang('改建')}</option>
                            {/eq}
                        </select>
                        <!-- <input type="text" name="school" class="form-control" datatype="s1-30">-->
                    </div>
                    <div class="form-group input-group  select-right">
                        <label class="input-group-addon">{:lang('项目学校')}</label>
                        <input type="text" name="school" class="form-control" datatype="s1-30" value="{$data.school}">
                    </div>
                    <div class="form-group   select-right">
                        <label>{:lang('建设内容')}</label>
                        <textarea name="content" cols="30" rows="7" class="form-control" datatype="s1-200">{$data.content}</textarea>
                    </div>
                </div>
            </div>

            <div class="form-group  text-center col-xs-8">
                <button class="btn btn-info" id="html" >{:lang('立即提交')}</button>
            </div>
        </form>

    </div>

</div>
{/block}
{block name="js"}
<!--日期-->
<link rel="stylesheet" href="__PUBLIC__/public/time/css/jedate.css">
<script src="__PUBLIC__/public/time/jquery.jedate.min.js"></script>

<script>
    (()=>{

        //选中事件
        $('#select').find('option').each(function () {
           if('{$data.type}' == $(this).val()){
                $(this).prop('selected','selected')
           }
        });
        //年份
        $("#date").jeDate({
            format: "YYYY"
        });
        //表单验证
        var form = $('form').Validform({
            tiptype:4,
            ajaxPost:true,

            beforeSubmit:function () {
                var sum = parseFloat($("input[name='money']").val()==''?0:$("input[name='money']").val());
                var valSum = 0;
                for (var i = 1; i < 5; i++) {
                    var hhh = $("input[name='address"+i+"']").val() == ''?0:$("input[name='address"+i+"']").val();
                    valSum = valSum+parseFloat(hhh);
                }
                if(sum == valSum){
                    layer.load(2);
                }
                else{
                    layer.msg("四项的合必须等于{:lang('规划资金')}");
                    return false;
                }
            },
            callback:function (da) {
                layer.closeAll();
                if(da == 1){
                    form.resetForm();
                    window.parent.location.reload(); //子窗口 刷新父页面
                    layer.msg('{:lang("成功")}',{icon:1});
                }
                else{
                    console.log(da);
                    layer.msg('{:lang("失败")}',{icon:2});
                }
            }

        });

        //上传文件



    })();
</script>
{/block}